<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" name="" id="user">
    <button id="save">持久存储</button>
</body>

</html>
<script>

    if(document.cookie){
        //处理cookie;
       
        user.value = document.cookie.split("; ")[0].split("=")[1];
    }                                   
    save.onclick = function () {
        var date = new Date();
        date.setTime(date.getTime() + 60 * 1000);
        //将日期转换成日期字符串；
        // var newDate = date.toUTCString()
        document.cookie = `username = ${user.value};expires = ${date.toUTCString()}`
    }
</script>